package org.chengn.level_middle.context1901;

/**
 * @Title: Context1901
 * @Author ChengN
 * @Package org.chengn.level_middle.context1901
 * @Date 2023/12/19 23:26
 * @description: 寻找峰值Ⅱ
 */
public class Context1901Error {
    int[][] moves = new int[][]{{0, 1}, {-1, 0}, {0, -1}, {1, 0}};
    public int[] findPeakGrid(int[][] mat) {
        int m = mat.length, n = mat[0].length;
        for (int i = 0; i < m; ++i) {
            int l = 0, r = n - 1;
            while (l <= r) {
                int mid = (l + r) >> 1;
                if (mid > 1 && mat[i][mid] < mat[i][mid - 1]) {
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
            }
//            System.out.println(i + "---" + l);
            boolean isRes = true;
            for (int[] move : moves) {
                int lTemp = i + move[0], uTemp = l + move[1];
                if (lTemp >= 0 && lTemp < m && uTemp >= 0 && uTemp < n && mat[lTemp][uTemp] > mat[i][l]) {
                    isRes = false;
                    break;
                }
            }
        }
        return new int[]{0, 0};
    }
}
